package com.wy.controller;

import com.wy.Service.HuzuService;
import com.wy.Service.ParkingService;
import com.wy.pojo.Huzu;
import com.wy.pojo.Parking;
import com.wy.pojo.Reside;
import com.wy.vo.HuzuDto;
import com.wy.vo.PageVo;
import com.wy.vo.ParkingDto;
import com.wy.vo.Result;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/parking")
@CrossOrigin
public class ParkingController {

    @Resource
    private ParkingService parkingService;

    String msg;

    @GetMapping("/list")
    public List<Parking>seach(){
        return parkingService.listAll();
    }
    @GetMapping("/search1")
    public Result search(Integer current, Integer pageSize){
        PageVo pageVo=parkingService.searchAll(current, pageSize);
        return Result.success(pageVo);
    }

    @GetMapping("/search2")
    public PageVo search(Integer current, Integer pageSize, ParkingDto dto){
        PageVo pageVo=parkingService.searchAll(current, pageSize,dto);
        return pageVo;
    }

    @GetMapping("/searchMaster")
    public Result searchMaster(){
        List<Reside> list=parkingService.searchReside();
        return Result.success(list);
    }

    @GetMapping("/add")
    public String add(Parking parking){
        try{
            parkingService.add(parking);
            msg="添加成功";
        }catch (Exception e){
            msg="添加失败";
        }
        return msg;
    }

    @GetMapping("/delete")
    public String delete(Integer id){
        try{
            parkingService.delete(id);
            msg="删除成功";
        }catch (Exception e){
            msg="删除失败";
        }
        return msg;
    }
    @GetMapping("/update")
    public String update(Parking parking){
        try{
            parkingService.update(parking);
            msg="修改成功";
        }catch (Exception e){
            msg="修改失败";
        }
        return msg;
    }


}
